package com.leo.base.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.Servlet;

/**
 * @ClassName CustomWebMvcConfigurer
 * @Description 限制请求后缀、过滤、拦截
 * @Author wangss
 * @date 2020.09.18 16:48
 * @Version 1.0
 */
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        // 开启路径后缀匹配
        configurer.setUseSuffixPatternMatch(true).setUseTrailingSlashMatch(true);
    }

    @Bean
    public ServletRegistrationBean<Servlet> servletRegistrationBean(DispatcherServlet servlet) {
        ServletRegistrationBean<Servlet> registrationBean = new ServletRegistrationBean<>(servlet);
        registrationBean.addUrlMappings("*.do");
        return registrationBean;
    }
}
